{
ID : phamnamlo2
PROB: wormhole
LANG: PASCAL
}

program wormhole;
const
  fi = 'wormhole.in';
  fo = 'wormhole.out';
  max = 500;
  maxc = 5200;
  maxq = 100000;
  oo = 1000000000;
var
  a, c : array[1..maxc] of longint;
  p : array[1..max+1] of longint;
  d, upd : array[1..max] of longint;
  n, m, w : longint;
  f : integer;

procedure inp;
var
  i, j : longint;
  x, y, z : array[1..maxc] of longint;
begin
  read(n, m, w);
  fillchar(p, sizeof(p), 0);
  for i := 1 to m do
  begin
    read(x[i], y[i], z[i]);
    inc(p[x[i]]);
    inc(p[y[i]]);
  end;
  j := m;
  for i := 1 to w do
  begin
    inc(j);
    read(x[j], y[j], z[j]);
    inc(p[x[j]]);
  end;
  for i := 2 to n+1 do inc(p[i], p[i-1]);
  for i := 1 to m  do
  begin
    a[p[x[i]]] := y[i];
    c[p[x[i]]] := z[i];
    a[p[y[i]]] := x[i];
    c[p[y[i]]] := z[i];
    dec(p[x[i]]);
    dec(p[y[i]]);
  end;
  j := m;
  for i := 1 to w do
  begin
    inc(j);
    a[p[x[j]]] := y[j];
    c[p[x[j]]] := -z[j];
    dec(p[x[j]]);
  end;
end;

procedure tang(var k : longint);
begin
  if k = maxq then k := 1
  else inc(k);
end;

procedure BFS(x : integer);
var
  q : array[1..maxq] of longint;
  j, l, r, u, v : longint;
begin
  fillchar(upd, sizeof(upd), 0);
  for u := 1 to n do d[u] := oo;
  d[x] := 0;
  q[1] := x;
  l := 1;
  r := 1;
  while true do
  begin
    u := q[l];
    for j := p[u]+1 to p[u+1] do
    begin
      v := a[j];
      if d[v] > d[u] + c[j] then
      begin
        d[v] := d[u] + c[j];
        if (v = x) and (d[v] < 0) then exit;
        tang(r);
        q[r] := v;
        inc(upd[u]);
        if upd[u] = n div 2 then
        begin
          d[x] := -1;
          exit;
        end;
      end;
    end;
    if l = r then break;
    tang(l);
  end;
end;

procedure process;
var
  u : longint;
begin
  for u := n downto 1 do
  begin
    BFS(u);
    if d[u] < 0 then
    begin
      writeln('YES');
      exit;
    end;
  end;
  writeln('NO');
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);

  read(f);
  while f > 0 do
  begin
    inp;
    process;
    dec(f);
  end;
  close(output);
  close(input);
end.
